<%@page import="news.entity.User"%>
<%@page import="news.biz.UserBiz"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
	
	String name=request.getParameter("username");
	String pwd=request.getParameter("userpwd");
	String autoLogin=request.getParameter("autoLogin");//多少天免登陆是否被选中，选择：on 未选择：null
	
	UserBiz userBiz=new UserBiz();
	User user=userBiz.userLogin(name, pwd);
	
	if(user!=null){
		
		if(autoLogin!=null){
			//创建cookie
			Cookie uname=new Cookie("uname",name);
			uname.setPath("/");
			uname.setMaxAge(60*60*24*14);
			//写入
			response.addCookie(uname);
			
			out.print("<script>alert('登陆成功')</script>");			
		}else{
			//创建session
			session.setAttribute("uname", name);
			out.print("<script>alert('登陆成功')</script>");			
		}
		request.getRequestDispatcher("../index.jsp").forward(request,response);
		
	}else{
		out.print("<script>alert('登录失败,请重试');location.href='login.jsp'</script>");	
	}
	
%>


